package com.woniuxy.happylife.suggest.service.impl;

import com.woniuxy.happylife.entity.Complaints;
import com.woniuxy.happylife.entity.ComplaintsDTO;
import com.woniuxy.happylife.suggest.config.MultipartFileToFile;
import com.woniuxy.happylife.suggest.dao.ComplaintsDao;
import com.woniuxy.happylife.suggest.service.ComplaintsService;

import com.woniuxy.happylife.suggest.service.IQiniuService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author Fu
 * @Date 2022-02-19 13:20
 */
@Service
public class ComplaintsServiceImpl implements ComplaintsService {
    @Resource
    ComplaintsDao complaintsDao;
    @Resource
    IQiniuService qiniuService;
    @Override
    public int insert(MultipartFile file, Complaints complaints) {
        Date date = new Date();
        complaints.setCreateTime(date);
        try {
            File toFile = MultipartFileToFile.multipartFileToFile(file);
            String url = qiniuService.uploadFile(toFile, file.getOriginalFilename() + date.getTime());
            complaints.setUrl(url);
            complaints.setImage(file.getOriginalFilename()+date.getTime());
            return complaintsDao.insert(complaints);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return 0;
    }

    @Override
    public List<Complaints> findAll(int businessId) {
        return complaintsDao.findAll(businessId);
    }

    @Override
    public int update(Complaints complaints) {
        return complaintsDao.updateType(complaints);
    }

    @Override
    public ComplaintsDTO findByCid(long complaintsId) {
        return complaintsDao.findByCid(complaintsId);
    }

    @Override
    public int deleteByComplaintsId(int complaints_id) {
        return complaintsDao.deleteByComplaintsId(complaints_id);
    }

    @Override
    public List<Complaints> findByCondition(Complaints complaints) {

        return complaintsDao.findByCondition(complaints);
    }
}
